package m3;

import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer;
import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyContext;
import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyStatus;
import org.apache.rocketmq.client.consumer.listener.MessageListenerConcurrently;
import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.common.message.MessageExt;

import java.util.List;

public class Consumer {
    public static void main(String[] args) throws MQClientException {
//        创建消费者实例
//        push是主动推送给客户端
//        pull是被动拉取
           DefaultMQPushConsumer c= new DefaultMQPushConsumer("consumer-group-3");
           c.setNamesrvAddr("192.168.64.141:9876");
           c.setMessageListener(new MessageListenerConcurrently() {
               @Override
               public ConsumeConcurrentlyStatus consumeMessage(List<MessageExt> list, ConsumeConcurrentlyContext consumeConcurrentlyContext) {
                   for (MessageExt mxt:list){
                       String s=new String(mxt.getBody());
                       System.out.println(":"+s);
                   }
//                   return ConsumeConcurrentlyStatus.CONSUME_SUCCESS;
                   System.out.println("处理失败");
                   return ConsumeConcurrentlyStatus.RECONSUME_LATER;
               }

           });

//        设置nameserver地址
            c.subscribe("Topic3", "*");
//        设置消息监听器
            c.start();
//        启动
    }
}
